<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";

const props = withDefaults(defineProps<FormProps>(), {
    formInline: () => ({
        startLocId: null,
        endLocId: null,
        agvId: null,
        batch: "",
        locState: 0,
        emptyTray: 0,
        outTaskCode: null,
        trayCode: null,
    }),
    formCargo: [],
    agvSelect: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const formCargo = ref(props.formCargo);
const agvSelect = ref(props.agvSelect);

function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
    <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="110px">
        <el-row :gutter="30">
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="起始货位" prop="startLocId">
                    <el-select v-model="newFormInline.startLocId" filterable clearable placeholder="请选择起始货位"
                        style="width:100%">
                        <el-option v-for="item in formCargo" :key="item.Code" :label="item.Code" :value="item.Id" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="终点货位" prop="endLocId">
                    <el-select v-model="newFormInline.endLocId" filterable clearable placeholder="请选择终点货位"
                        style="width:100%">
                        <el-option v-for="item in formCargo" :key="item.Code" :label="item.Code" :value="item.Id" />
                    </el-select>
                </el-form-item>
            </re-col>

            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="货位状态" prop="locState">
                    <el-switch v-model="newFormInline.locState" width="60"
                        style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" inline-prompt
                        :active-value="1" :inactive-value="0" active-text="启用" inactive-text="禁用" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="补充空托盘" prop="emptyTray">
                    <el-switch v-model="newFormInline.emptyTray" width="60"
                        style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" inline-prompt
                        :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="车辆" prop="agvId">
                    <el-select v-model="newFormInline.agvId" filterable clearable placeholder="请选择车辆"
                        style="width:100%">
                        <el-option v-for="item in agvSelect" :key="item.AgvId" :label="item.AgvName"
                            :value="item.AgvId">
                        </el-option>
                    </el-select>
                </el-form-item>
            </re-col>
            <!-- <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="batch" prop="batch">
          <el-input v-model="newFormInline.batch" clearable placeholder="请输入batch" />
        </el-form-item>
      </re-col> -->
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="第三方任务编码" prop="outTaskCode">
                    <el-input v-model="newFormInline.outTaskCode" clearable placeholder="请输入第三方任务编码" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="托盘编码" prop="trayCode">
                    <el-input v-model="newFormInline.trayCode" clearable placeholder="请输入托盘编码" />
                </el-form-item>
            </re-col>
        </el-row>
    </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
    margin-right: 16px;
}
</style>
